-------------------------------------------------------------------------------------
-- -*- coding: utf-8 -*-
--
-- @author:   zxf
-- @email:    07291@qq.com
-- @date:     2024/8/23
-- @module:   treeArr_base
-- @describe:
-- @version:  v1.0
--

-------------------------------------------------------------------------------------

---@type load_tree
local load_tree = import('bt/bt_framework/func/load_tree')

---@class treeArr_base
local treeArr_base = {}

function treeArr_base:set_arr(arr)
    self.treeArr = arr
end

function treeArr_base:init(ctx, owner)
    if self.treeArr then
        self.isInit = true
        self.ctx = ctx
        self.owner = owner
        for k, v in ipairs(self.treeArr) do
            v.tree = load_tree.get_tree(v.name, v.pathName, ctx, owner)
        end
    end
end

function treeArr_base:breakCond()
    return false
end

function treeArr_base:interrupt()
    print('中断树')
    for k, v in ipairs(self.treeArr) do
        v.tree:interrupt()
    end
end

function treeArr_base:run()
    if not self.isInit then
        return
    end
    for k, v in ipairs(self.treeArr) do
        if self:breakCond() then
            break
        end
        v.tree:run()
    end
end

function treeArr_base:new()
    local ret = {}
    self.__index = self
    setmetatable(ret, self)
    return ret
end

return treeArr_base